$(function(){
	//获取个人资料，
	loadDetailMessageByBasic_id();
	loadAlter();
	
	$("#alterBut").click(function(){
		$(".alterDiv").hide();
	});
	 $("#myNav").affix({
	        offset: { 
	            top: 125 
	      }
	 });
});

function loadDetailMessageByBasic_id(){
	utilAjax("/basic_information/queryDetailMessageByBasic_id","","post",function(data){
		$("#fileImg").attr("src","/image/"+data.basic_photo);
		$("#basic_id").val(data.basic_id);
		$("#basic_name").val(data.basic_name);
		$("#basic_email").val(data.basic_email);
		$("#basic_phone").val(data.basic_phone);
		$("#basic_card").val(data.basic_card);
		$("#rec_address").val(data.rec_address);
		$("#basic_job_state [value='"+data.basic_job_state+"']").attr("selected",true);
	});
}

var imgurl = "";
function getImgURL(node) {	
	var imgURL = "";	
    try{
        var file = null;
        if(node.files && node.files[0] ){
        	file = node.files[0]; 
        }else if(node.files && node.files.item(0)) {                    			
        	file = node.files.item(0);   
        } 	
        try{
			imgURL =  file.getAsDataURL();  
        }catch(e){
        	imgRUL = window.URL.createObjectURL(file);
        }
     }catch(e){     		
        if (node.files && node.files[0]) {                    		
        	var reader = new FileReader(); 
        	reader.onload = function (e) {                      	        	
        	    imgURL = e.target.result;  
        	};
        	reader.readAsDataURL(node.files[0]); 
        }  
     }
	creatImg(imgRUL);
	return imgURL;
}
function creatImg(imgRUL){   //根据指定URL创建一个Img对象
	$("#fileImg").attr("src",imgRUL);
}


function loadAlter(){
	var alterCon = $("#alterContent").text();
	if(alterCon!=""){
		$(".alterDiv").show();
		var interval = setInterval(function(){
			$(".alterDiv").hide();
			$("#alterContent").text("");
			clearInterval(interval);
		},3000);
	}
}

function utilAjax(url,data,type,success){
	$.ajax({
		url:url,
		data:data,
		dataType:'json',
		type:type,
		success:success,
		error:function(){
		}
	});
}


function checkImgMyFile(){
	//判断文本域是否有值  并判断是否是图片
	var myFile = $('#myFile').get(0).files[0];
	var reader = new FileReader();// 操作图片
	if(myFile==undefined){
		$('#myFile').css("border","1px solid red");
		$("#alterContent").text("请选择头像！！！");
		loadAlter()
		return false;
	}else{
		var imageType = $('#myFile').get(0).files[0].type;
		if(imageType.substring(0,imageType.indexOf("/"))!="image"){
			$('#myFile').css("border","1px solid red");
			$("#alterContent").text("请选择图片类型的文件！！！");
			loadAlter()
			return false;
		}else{
			 $("#myFile").css("border", "");
			return true;
		}
	}
	return false;	
}



function checkJiu_ps(){
	//判断旧密码
	var jiu_ps = $("#jiu_ps").val();
	if(jiu_ps==""){
		$("#alterContent").text("旧密码不能为空！！！");
		$("#jiu_ps").css("border","1px solid red");
		loadAlter();
		return false;
	}else{
		$("#jiu_ps").css("border",""); 
		return true
	}
}


function checkBasic_password(){
	//判断新密码
	var basic_password = $("#basic_password").val();
	if (basic_password.length < 6 || basic_password.length > 20) {
		// 密码非法,加一个红色边框
		$("#basic_password").css("border", "1px solid red");
		$("#alterContent").html("密码长度不能小于6位，且不能大于20位！！！");
		loadAlter();
		return false;
	} else {
		// 密码合法
		$("#basic_password").css("border", "");
		return true;
	}
}
function checkBasic_password2(){
	//确认新密码
	var basic_password2 = $("#basic_password2").val();
	var basic_password = $("#basic_password").val();
	if(basic_password2!=basic_password){
		$("#alterContent").text("两次密码不一致！！！");
		$("#basic_password").css("border","1px solid red");
		$("#basic_password2").css("border","1px solid red");
		loadAlter();
		return false;
	}else{
		$("#basic_password").css("border","");
		$("#basic_password2").css("border","");
		return true;
	}
}
function checkUpdatePassword(){
	if(checkJiu_ps() && checkBasic_password() && checkBasic_password2()){
		return true;
	}
	return false;
}